setClass("PHTestBFrameworkFinalResult",contains="VBFrameworkFinalResult",
		representation(
				.significanceLevel="numeric",
				.hTester ="VHtester"
		),
		prototype=prototype(
				.description="All pairs Hypothesis test  Bootstrap Framework Final Result computer class",
				.significanceLevel = 0.05
		
		),
		validity=function(.Object){
			if(.Object@.significanceLevel <=0 || .Object@.significanceLevel>=1 ){
				stop("significanceLevel must be in (0,1)")
			}
		}

)  


#initialization method 
setMethod("initialize",
		signature="PHTestBFrameworkFinalResult",
		function(.Object,hTester,significanceLevel=0.05,...){
			.Object<-callNextMethod(.Object,...)
			.Object@.hTester <- hTester
			.Object@.significanceLevel <-significanceLevel
			return(.Object)
		})


setMethod("computeBFResult",
		signature="PHTestBFrameworkFinalResult",
		definition=function(.Object,inputList,...){
			#check inputList format
			callNextMethod(.Object,inputList,...)
			
			listLength <- length(inputList)
			#make output matrix
			outMatrixFieldsNumber <- listLength^2
			outMatrix <- matrix(rep(0,outMatrixFieldsNumber),ncol=listLength)
			#get names of rows and columns
			crNames <- unlist( lapply(1:listLength,FUN=function(n,list){
						rownames(list[[n]])
					} ,inputList))
			colnames(outMatrix) <- crNames
			rownames(outMatrix) <- crNames
			#make pair test grid
			gri <-expand.grid(1:listLength,1:listLength)
			gri <- gri[which(gri$Var1 > gri$Var2),]
			for(i in 1:nrow(gri)){
				pval <-htest(.Object@.hTester,inputList[[gri[i,1]]],inputList[[gri[i,2]]])
				#fill outputMatrix
				outMatrix[gri[i,1],gri[i,2]] <-pval
				outMatrix[gri[i,2],gri[i,1]] <-pval
			}
			diag(outMatrix)<- rep(1,listLength)
			outBoolMatrix <- matrix(outMatrix>.Object@.significanceLevel,ncol=listLength)
			colnames(outBoolMatrix) <- crNames
			rownames(outBoolMatrix) <- crNames
			
			return(list(PVal=outMatrix,Bool=outBoolMatrix,OrgData=inputList))
		}
)  

